function CalendarSettingRepository() {
    this._proxy = new DtoProxy();
    this._lastVisitedMonth = [];
    this._isSendingLastVisitedMonth = false;
    this._lastVisitedMonthStatus = null;

    var me = this;
    setInterval(function() {
        me._sendLastVisitedMonth();
    }, pwcconfig.CALENDAR_AUTO_SAVE_LAST_VISITED_MONTH_INTERVEL);
}

CalendarSettingRepository.prototype = {

    saveLastVisitedMonth: function(calendarHeaderStatus) {
        this._lastVisitedMonth.push(calendarHeaderStatus);
    },

    _hasNewLastVisitedMonthPending: function(headerStatus) {
        if (this._lastVisitedMonth.length == 0) {
            return false;
        }

        if (headerStatus.isSameWith(this._lastVisitedMonthStatus)) {
            return false;
        }

        return true;
    },

    _sendLastVisitedMonth: function() {
        var headerStatus = this._lastVisitedMonth[this._lastVisitedMonth.length - 1];
        if (this._isSendingLastVisitedMonth ||
           !this._hasNewLastVisitedMonthPending(headerStatus)) {
            return;
        }
        this._doSendLastVisitedMonth(headerStatus);
    },

    _doSendLastVisitedMonth: function(headerStatus) {
        var me = this;
        this._lastVisitedMonth = [];
        this._isSendingLastVisitedMonth = true;
        this._proxy.saveLastVisitedMonthAsync(
                headerStatus.firstVisibleYearMonth.toDto(),
                headerStatus.selectedYearMonth.toDto(),
                function() {
                    me._isSendingLastVisitedMonth = false;
                    me._lastVisitedMonthStatus = headerStatus;
                }
        );
    }
};


